<template>
  <div v-loading="containerLoading" class="app-container">
    <el-row class="activity">
      <el-col :span="22" :offset="1" class="actions">
        <h2 class="activity-title">
          {{ activity.ac_name }}
          <el-tag :type="activity | statusTagType" size="mini">{{ activity.ac_state | formateActivityState }}</el-tag>
          <el-tag v-if="activity.ac_type === 1" type="success" size="mini">快捷活动</el-tag>
          <el-tag v-if="$store.getters.menuList.hd_activity_join" :type="activity.bm ? 'success' : 'info'" size="mini">{{ activity.bm ? '已报名' : '未报名' }}</el-tag>
          <el-tag
            v-if="$store.getters.menuList.hd_activity_join && activity.bm && [5010, 6, 7].indexOf(activity.ac_state) > -1"
            :type="activity.yz ? 'success' : 'info'"
            size="mini">
            {{ activity.yz ? '已认证' : '未认证' }}
          </el-tag>
        </h2>
        <el-button-group v-if="activity.ac_type === 0">
          <!-- 活动报名 -->
          <el-button
            v-if="$store.getters.menuList.hd_activity_join && activity.ac_state === 3"
            :disabled="applyBtn.disabled"
            :loading="applyBtn.loading"
            size="mini"
            icon="el-icon-plus"
            @click="handleApply">
            {{ applyBtn.status[applyBtn.index] }}
          </el-button>
          <!--活动验证码认证-->
          <el-button
            v-if="$store.getters.menuList.hd_code_verify && activity.ac_verify === 1 && activity.bm === 1"
            :disabled="activity.yz === 1 || activity.ac_state !== 6 || activity.bm === 0"
            :loading="activityCodeLoading"
            size="mini"
            icon="el-icon-location"
            @click="handleStuVerifyCode">
            {{ activity.yz ? '已认证' : '验证码认证' }}
          </el-button>

          <!-- 学生二维码认证 -->
          <el-button
            v-if="$store.getters.menuList.hd_qrcode_verify && activity.ac_verify === 2 && activity.ac_state === 5010"
            size="mini"
            icon="el-icon-menu"
            @click="handleShowQrcodeTip">
            二维码认证
          </el-button>
        </el-button-group>
        <el-button-group v-if="userInfo.role_id === 2 || userInfo.role_id === 3">
          <el-button
            v-if="$store.getters.menuList.hd_submit_verify && activity.ac_admID === userInfo.user_id && (activity.ac_state === 1 || activity.ac_state === 4)"
            :disabled="submitBtn.disabled"
            :loading="submitBtn.loading"
            size="mini"
            icon="el-icon-upload2"
            @click="handleSubmit">
            {{ submitBtn.status[submitBtn.index] }}
          </el-button>

          <el-button
            v-if="$store.getters.menuList.hd_activity_publish && activity.ac_state === 2"
            :disabled="verifyBtn.disabled"
            size="mini"
            icon="el-icon-view"
            @click="handleVerify">
            {{ verifyBtn.status[verifyBtn.index] }}
          </el-button>

          <el-button
            v-if="$store.getters.menuList.hd_activity_edit && activity.ac_admID === userInfo.user_id && (activity.ac_state === 1 || activity.ac_state === 4)"
            size="mini"
            icon="el-icon-edit"
            @click="handleEdit">
            编辑
          </el-button>

          <el-button
            v-if="$store.getters.menuList.hd_gen_code && activity.ac_admID === userInfo.user_id && activity.ac_type === 0 && ((activity.ac_verify === 2 && [5, 5010].indexOf(activity.ac_state) > -1) || (activity.ac_verify === 1 && [5, 5010, 6].indexOf(activity.ac_state) > -1))"
            :disabled="activityGenCode.disabled"
            size="mini"
            icon="el-icon-document"
            @click="handleGenCode">
            {{ activityGenCode.status[activityGenCode.index] }}
          </el-button>

          <el-button
            v-if="$store.getters.menuList.hd_export_code && activity.ac_admID === userInfo.user_id && activity.ac_verify === 1 && [5,5010,6].indexOf(activity.ac_state) > -1"
            :disabled="!activity.codeNumber"
            size="mini"
            icon="el-icon-download"
            @click="exprotCodeExcel">
            导出验证码
          </el-button>

          <el-button
            v-if="$store.getters.menuList.hd_qrcode_show && activity.ac_admID === userInfo.user_id && activity.ac_verify === 2 && activity.ac_state === 5010"
            :disabled="!activity.codeNumber"
            size="mini"
            icon="el-icon-view"
            @click="showQrcode = true">
            展示活动二维码
          </el-button>

          <el-button
            v-if="$store.getters.menuList.hd_import_activity_score && activity.ac_type === 1"
            size="mini"
            icon="el-icon-download">
            <a href="/api/activity/template.zepc" target="_blank">下载快捷活动学分模板</a>
          </el-button>

          <el-button
            v-if="$store.getters.menuList.hd_import_activity_score && activity.ac_admID === userInfo.user_id && activity.ac_type === 1 && activity.ac_state === 1"
            size="mini"
            icon="el-icon-upload2"
            @click="uploadDialogVisible = true">
            导入快捷活动学分
          </el-button>

          <el-button
            v-if="$store.getters.menuList.hd_activity_delete && activity.ac_admID === userInfo.user_id"
            size="mini"
            icon="el-icon-delete"
            @click="handleDelete">
            删除
          </el-button>
        </el-button-group>
      </el-col>
    </el-row>
    <el-row class="field-items">
      <el-col :md="15" :offset="1" :xs="22" :sm="22">
        <el-row :gutter="20">
          <el-col :md="12" :xs="24" :sm="24" class="left-row-panel">
            <el-row>
              <el-col :span="8">活动所在学年:</el-col>
              <el-col :span="16">{{ activity.ac_year }}</el-col>
            </el-row>
            <el-row>
              <el-col :span="8">活动所在学期:</el-col>
              <el-col :span="16">第{{ activity.ac_term }}学期</el-col>
            </el-row>
            <el-row>
              <el-col :span="8">活动验证方式:</el-col>
              <el-col :span="16">
                <span v-if="activity.ac_verify === 1">验证码</span>
                <span v-if="activity.ac_verify === 2">二维码</span>
              </el-col>
            </el-row>
            <el-row>
              <el-col :span="8">活动学分:</el-col>
              <el-col :span="16">{{ activity.ac_credit }}</el-col>
            </el-row>
            <el-row>
              <el-col :span="8">活动版块:</el-col>
              <el-col :span="16">{{ activity.ac_classify | formateClassify }}</el-col>
            </el-row>
            <el-row>
              <el-col :span="8">投放性别:</el-col>
              <el-col :span="16">{{ activity.ac_range_sex | formatSex }}</el-col>
            </el-row>
            <el-row>
              <el-col :span="8">投放班级:</el-col>
              <el-col :span="16">
                <el-button type="text" style="padding: 0" @click="showRangeClassDetail = true">查看全部</el-button>
              </el-col>
            </el-row>
          </el-col>

          <el-col :md="12" :xs="24" :sm="24" class="left-row-panel">
            <el-row>
              <el-col :span="8">活动地点:</el-col>
              <el-col :span="16">{{ activity.ac_site }}</el-col>
            </el-row>
            <el-row>
              <el-col :span="8">活动人数上限:</el-col>
              <el-col :span="16">{{ activity.ac_number }}<span>（已报名{{ activity.enrollment || 0 }}人）</span> </el-col>
            </el-row>
            <el-row>
              <el-col :span="8">开始时间:</el-col>
              <el-col :span="16">{{ activity.ac_begin }}</el-col>
            </el-row>
            <el-row>
              <el-col :span="8">结束时间:</el-col>
              <el-col :span="16">{{ activity.ac_end }}</el-col>
            </el-row>
            <el-row>
              <el-col :span="8">截止报名时间:</el-col>
              <el-col :span="16">{{ activity.ac_locktime }}</el-col>
            </el-row>
            <el-row>
              <el-col :span="8">活动完结时间:</el-col>
              <el-col :span="16">{{ activity.ac_overtime }}</el-col>
            </el-row>
          </el-col>
        </el-row>
      </el-col>
      <el-col :md="6" :offset="1" :xs="22" :sm="22">
        <el-row :gutter="10" class="activity-items">
          <el-col :span="8" :sm="8">主办单位:</el-col>
          <el-col :span="16" :sm="16">{{ activity.ac_host }}</el-col>
        </el-row>
        <el-row :gutter="10" class="activity-items">
          <el-col :span="8" :sm="8">承办单位:</el-col>
          <el-col :span="16" :sm="16">{{ activity.ac_organizer }}</el-col>
        </el-row>
        <el-row :gutter="10" class="activity-items">
          <el-col :span="8" :sm="8">指导老师:</el-col>
          <el-col :span="16" :sm="16">{{ activity.ac_teacher }}</el-col>
        </el-row>
        <el-row :gutter="10" class="activity-items">
          <el-col :span="8" :sm="8">活动创建人:</el-col>
          <el-col :span="16" :sm="16">{{ activity.ac_admname }}</el-col>
        </el-row>
        <el-row :gutter="10" class="activity-items">
          <el-col :span="8" :sm="8">活动负责人:</el-col>
          <el-col :span="16" :sm="16">{{ activity.ac_leader }}</el-col>
        </el-row>
        <el-row :gutter="10" class="activity-items">
          <el-col :span="8" :sm="8">负责人电话:</el-col>
          <el-col :span="16" :sm="16">{{ activity.ac_phone }}</el-col>
        </el-row>
      </el-col>
    </el-row>
    <el-row v-if="userInfo.role_id !== 1 && activity.ac_state === 4">
      <el-col :span="15" :xs="22" :sm="15" :offset="1" class="introduce">
        <h4 style="color: red;">审批意见:</h4>
        <div class="introduce-datail" v-html="activity.ac_opinion"/>
      </el-col>
    </el-row>
    <el-row>
      <el-col :span="22" :offset="1" class="introduce">
        <h3 class="sub-title">活动介绍:</h3>
        <div class="introduce-datail" v-html="activity.ac_introduce"/>
      </el-col>
    </el-row>
    <el-row
      v-if="SignInVisible"
      class="introduce">
      <el-col :span="22" :offset="1">
        <h3 class="sub-title">报名学生名单:</h3>
        <sign-in-table :ac-id="$route.params.id.toString()" :user-info="userInfo" :activity="activity"/>
      </el-col>
    </el-row>
    <field-dialog
      :visible="dialogFormVisible"
      :dialog-model="dialogModel"
      mode="edit"
      @change-visible="handleDialogVisible"
    />
    <el-dialog
      :visible="openVerifyDialog"
      width="30%"
      title="活动审批">
      <div style="line-height: 24px; margin-bottom: 20px;">请检查活动信息是否准确完整，如果批准当前活动，学生可以立即开始报名当前活动，如果当前活动不予以批准，请填写审批指导意见。</div>
      <div style="line-height: 24px; margin-bottom: 20px; text-align: center">
        <el-radio-group v-model="verifyActivity">
          <el-radio :label="3">通过</el-radio>
          <el-radio :label="4">不通过</el-radio>
        </el-radio-group>
      </div>
      <div>
        <el-input
          v-show="verifyActivity === 4"
          :autosize="{ minRows: 3, maxRows: 4}"
          v-model="verifyActivityOption"
          type="textarea"
          placeholder="请填写审批指导意见"/>
      </div>
      <span slot="footer" class="dialog-footer">
        <el-button @click="openVerifyDialog = false">取 消</el-button>
        <el-button :disabled="verifyActivity === 4 && !verifyActivityOption" type="primary" @click="handlePostActivity">确 定</el-button>
      </span>
    </el-dialog>
    <el-dialog
      :visible.sync="showRangeClassDetail"
      title="活动投放班级范围"
      class="range-class"
      width="30%">
      <h4 v-if="$store.getters.menuList.hd_activity_join" style="margin-top: 0">提示：当前活动的投放范围<span style="color: red">{{ includeCurrentClass ? '包含' : '不包含' }}</span>您所在的班级。</h4>
      <div style="min-height: 250px;max-height: 270px;overflow-y: auto">
        <el-input v-model="filterClass" placeholder="输入关键字进行过滤"/>
        <el-tree
          ref="classTree"
          :data="classData"
          :default-expanded-keys="[$store.getters.userInfo.bmmc]"
          :filter-node-method="filterNode"
          node-key="id"
          accordion
          highlight-current
          style="margin-top: 20px"/>
      </div>
      <span slot="footer" class="dialog-footer">
        <el-button @click="showRangeClassDetail = false">关闭</el-button>
      </span>
    </el-dialog>

    <qrcode-dialog :visible="showQrcode" :activity="activity" @close="showQrcode = false"/>
    <upload-file :visible="uploadDialogVisible" @close="uploadDialogVisible = false"/>
  </div>
</template>

<script>
import fieldDialog from './fieldDialog'
import qrcodeDialog from './qrcodeDialog'
import uploadFile from './uploadFile'
import signInTable from './signInTable'
import { formatClassTree } from '@/utils/index.js'
import { getActivityDetail, deleteActivity, joinActivity, sendToVerify, publishActivity, verifyActivityQrCode, genActivityCode, verifyActivityCode, getClassData } from '@/api/activity'

export default {
  components: { fieldDialog, qrcodeDialog, uploadFile, signInTable },
  data() {
    return {
      containerLoading: false,
      activity: {},
      tempRoute: {},
      dialogModel: {},
      userInfo: null,
      verifyActivity: 3,
      showQrcode: false,
      showRangeClassDetail: false,
      verifyActivityOption: null,
      dialogFormVisible: false,
      openVerifyDialog: false,
      uploadDialogVisible: false,
      SignInVisible: false,
      classData: [],
      filterClass: '',
      includeCurrentClass: false,
      applyBtn: {
        disabled: true,
        status: ['立即报名', '已报名', '不可报名'],
        index: 0,
        loading: false
      },
      submitBtn: {
        disabled: true,
        status: ['提交审批', '已提交审批'],
        index: 0,
        loading: false
      },
      verifyBtn: {
        disabled: true,
        status: ['活动审批', '已发布'],
        index: 0,
        loading: false
      },
      activityGenCode: {
        disabled: true,
        status: ['生成活动验证码', '活动验证码已生成'],
        index: 0
      },
      checkTimer: null,
      activityCodeLoading: false
    }
  },
  watch: {
    filterClass(val) {
      this.$refs.classTree.filter(val)
    }
  },
  created() {
    this.tempRoute = Object.assign({}, this.$route)
    this.userInfo = this.$store.getters.userInfo
    this.getActivityDetail()
  },
  mounted() {
    this.$on('updateList', () => {
      this.getActivityDetail()
      this.handleDialogVisible(false)
    })

    clearInterval(this.checkTimer)
  },
  destroyed() {
    clearInterval(this.checkTimer)
  },
  methods: {
    handleApply() {
      this.$confirm('在报名活动前请仔细阅读活动信息，确认报名此活动?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        this.applyBtn.loading = true
        joinActivity(this.$route.params.id.toString())
          .then(res => {
            let type = 'warning'
            if (res.code === 200) {
              type = 'success'
            }
            this.$message({ message: res.msg, type })
            this.getActivityDetail()
          })
          .catch(() => {
            this.$message({ type: 'error', message: '活动报名失败，请重试。' })
          })
          .finally(() => {
            this.applyBtn.loading = false
          })
      }).catch(() => {})
    },
    handleSubmit() {
      this.$confirm('在提交审核前请仔细确认活动信息完整无误，确认提交审核活动?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        this.submitBtn.loading = true
        sendToVerify(this.activity.ac_id.toString())
          .then(res => {
            if (res.code === 200) {
              this.$message({ type: 'success', message: '已成功提交审核此活动！' })
              this.getActivityDetail()
            } else {
              this.$message({ type: 'error', message: '活动提交失败，请联系管理员。' })
            }
          })
          .catch(() => {
            this.$message({ type: 'error', message: '活动提交失败，请联系管理员。' })
          })
          .finally(() => {
            this.submitBtn.loading = false
          })
      })
        .catch(() => {})
    },
    handleVerify() {
      this.openVerifyDialog = true
    },
    handlePostActivity() {
      if (this.verifyActivity) {
        this.$confirm('确认保存当前审核结果?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          publishActivity(
            this.activity.ac_id.toString(),
            this.verifyActivity.toString(),
            this.verifyActivityOption
          ).then(res => {
            if (res.code === 200) {
              this.getActivityDetail()
              this.$message({
                type: 'success',
                message: '审核结果保存成功!'
              })
            }
          }).catch(() => {})
          this.openVerifyDialog = false
        }).catch(() => {})
      }
    },
    handleEdit() {
      this.handleDialogVisible(true)
    },
    transFormData() {
      const data = {}
      const mapper = {
        AcName: 'ac_name',
        AcSite: 'ac_site',
        AcType: 'ac_type',
        AcClassify: 'ac_classify',
        AcCredit: 'ac_credit',
        AcNumber: 'ac_number',
        AcVerify: 'ac_verify',
        AcYear: 'ac_year',
        AcTerm: 'ac_term',
        AcBegin: 'ac_begin',
        AcEnd: 'ac_end',
        AcLocktime: 'ac_locktime',
        AcIntroduce: 'ac_introduce',
        AcHost: 'ac_host',
        AcOrganizer: 'ac_organizer',
        AcTeacher: 'ac_teacher',
        AcLeader: 'ac_leader',
        AcPhone: 'ac_phone',
        AcRangeSex: 'ac_range_sex',
        AcRangeClass: 'ac_range_class',
        AcOvertime: 'ac_overtime'
      }
      Object.keys(mapper).map(key => {
        data[key] = this.activity[mapper[key]]
      })
      data.AcId = this.activity.ac_id.toString()
      data.AcClassify = data.AcClassify.toString()
      data.AcTerm = data.AcTerm.toString()
      data.AcRangeClass = data.AcRangeClass.split(',')
      data.AcRangeTime = [data.AcBegin, data.AcEnd]
      this.dialogModel = data
    },
    handleDialogVisible(value) {
      this.dialogFormVisible = value
    },
    handlePublish() {
      this.$message({
        message: '发布成功',
        type: 'success'
      })
      // row.status = '已发布'
    },
    handleDelete() {
      const defaultText = '此操作将永久删除该活动, 是否继续?'
      const fastText = '此操作将永久删除该活动, 并且将清楚当前活动所得学分, 是否继续?'
      const text = this.activity.ac_type === 1 ? fastText : defaultText
      this.$confirm(text, '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        deleteActivity(this.$route.params.id.toString()).then(res => {
          if (res.code !== 201) {
            deleteSuccess.apply(this)
          } else {
            this.$message({
              message: '活动删除失败',
              type: 'error'
            })
          }
        }).catch(() => {})
      }).catch(() => {})

      function deleteSuccess() {
        this.$message({
          message: '活动删除成功',
          type: 'success'
        })
        this.deleteView()
      }
    },
    handleGenCode() {
      this.$confirm('此操作将在后台生成活动验证码，已报名学生可以在学生端对当前活动进行认证, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        genActivityCode(this.activity.ac_id.toString()).then(res => {
          let msg = {}
          if (res.code === 200) {
            msg = {
              type: 'success',
              message: '生成活动验证码成功，请根据活动时间通知学生认证当前活动!',
              duration: 5000
            }
            this.getActivityDetail()
          } else {
            msg = {
              type: 'error',
              message: res.msg
            }
          }
          this.$message(msg)
        }).catch(() => {})
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消生成'
        })
      })
    },
    deleteView() {
      this.$store.dispatch('delView', this.tempRoute).then(({ visitedViews }) => {
        const latestView = visitedViews.slice(-1)[0]
        if (latestView) {
          this.$router.push(latestView)
        } else {
          this.$router.push('/')
        }
      })
    },
    setTagsViewTitle() {
      const title = this.activity.ac_name
      const route = Object.assign({}, this.tempRoute, { title: `${title}` })
      this.$store.dispatch('updateVisitedView', route)
    },
    getActivityDetail() {
      this.containerLoading = true
      const id = this.$route.params.id.toString()
      this.applyBtn.disabled = false
      this.verifyBtn.disabled = false
      this.submitBtn.disabled = false
      getActivityDetail(id).then(res => {
        try {
          this.activity = this.formatActivityDetail(res.data)
          this.checkActivityButton()
          this.transFormData()
          this.autoCheckApply()
          this.checkSignInVisible()
          this.handleVerifyCode()
          this.getClassData()
          this.setTagsViewTitle()
        } catch (e) {
          console.log(e)
        }
      })
        .catch(() => {})
        .finally(() => {
          this.containerLoading = false
        })
    },
    formatActivityDetail(data) {
      if (data.ac_range_grade) {
        data.ac_range_grade = data.ac_range_grade.replace(/,/g, '、')
      }

      this.includeCurrentClass = new RegExp(`(^|,)${this.$store.getters.userInfo.bmmc}(,|$)`).test(data.ac_range_class)

      return data
    },
    checkActivityButton() {
      if (!Object.keys(this.activity).length) {
        return false
      }

      if (this.activity.ac_range_sex !== 0 && this.activity.ac_range_sex !== parseInt(this.$store.getters.userInfo.sex)) {
      // 判断性别
        this.applyBtn.disabled = true
        this.applyBtn.index = 2
      } else if (!this.includeCurrentClass) {
      // 判断班级
        this.applyBtn.disabled = true
        this.applyBtn.index = 2
      } else if (new Date(this.activity.ac_locktime) < new Date()) {
        // 判断报名时间
        this.applyBtn.disabled = true
        this.applyBtn.index = 2
      } else {
        this.applyBtn.disabled = false
        this.applyBtn.index = 0
      }

      // 判断是否已报名
      if (this.activity.bm) {
        this.applyBtn.disabled = true
        this.applyBtn.index = 1
      }

      // 判断已生成活动验证码
      if (this.activity.codeNumber === 0) {
        this.activityGenCode.disabled = false
        this.activityGenCode.index = 0
      } else {
        this.activityGenCode.disabled = true
        this.activityGenCode.index = 1
      }
    },
    handleVerifyCode() {
      const code = this.$route.query.verifycode
      if (code && this.$store.getters.menuList.hd_qrcode_verify && this.activity.ac_verify === 2) {
        this.$confirm('已扫描到活动验证码，点击【确定】按钮以验证活动', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          this.verifyCode(window.atob(code))
        }).catch(() => {
          this.$message({
            type: 'info',
            message: '取消验证活动'
          })
        })
      }
    },
    verifyCode(code) {
      if (code) {
        verifyActivityQrCode(this.$route.params.id.toString(), code).then(res => {
          if (res.code === 200) {
            this.getActivityDetail()
            this.$message({ type: 'success', message: '活动验证成功' })
          } else {
            this.$message({ type: 'error', message: res.msg })
          }
        })
          .catch(() => {})
          .finally(() => {
            // 取消验证码参数
            this.$router.replace({
              name: 'ActivityDetail'
            })
          })
      }
    },
    autoCheckApply() {
      this.checkTimer = setInterval(() => {
        this.checkActivityButton()
      }, 1000)
    },
    exprotCodeExcel() {
      // 创建隐藏的可下载链接
      const eleLink = document.createElement('a')
      eleLink.target = '_blank'
      eleLink.href = `/api/activity/derivecode.zepc?AcId=${this.$route.params.id}`
      // 触发点击
      document.body.appendChild(eleLink)
      eleLink.click()
      // 然后移除
      document.body.removeChild(eleLink)
    },
    handleShowQrcodeTip() {
      this.$confirm('请打开手机扫一扫功能，扫描活动现场的二维码，如果有任何疑问请联系活动负责人。', '提示')
    },
    handleStuVerifyCode() {
      this.$prompt('请输入活动验证码', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        inputPattern: /^[A-z0-9]{8}$/,
        inputErrorMessage: '验证码格式不正确'
      }).then(({ value }) => {
        this.activityCodeLoading = true
        verifyActivityCode(this.activity.ac_id.toString(), value).then(res => {
          let type = 'error'
          if (res.code === 200) {
            type = 'success'
            this.getActivityDetail()
          }
          this.activityCodeLoading = false
          this.$message({ type, message: res.msg })
        })
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '取消认证'
        })
      })
    },
    checkSignInVisible() {
      let statusArr = [3, 5, 5010, 6, 7]

      // 快捷活动增加显示范围
      if (this.activity.ac_type === 1) {
        statusArr = statusArr.concat([1, 2])
      }

      const stateEnabled = statusArr.indexOf(this.activity.ac_state) > -1
      const authEnabled = this.$store.getters.menuList.hd_signIn_table
      this.SignInVisible = stateEnabled && authEnabled
    },
    getClassData() {
      getClassData()
        .then(res => {
          this.classData = formatClassTree(res.data, this.activity.ac_range_class)
        })
        .catch(() => {})
    },
    filterNode(value, data) {
      if (!value) return true
      return data.label.indexOf(value) !== -1
    }
  }
}
</script>

<style lang="scss" scoped>
.app-container .actions {
  margin-bottom: 10px;
}

.app-container .actions .el-button-group .el-button,
.activity-items .el-col,
.left-row-panel > .el-row {
  margin-bottom: 10px;
}
.field-items,
.introduce {
  font-size: 14px;
}

.activity-title {
  font-size: 20px;
}

.left-row-panel > .el-row > .el-col,
.activity-items > .el-col,
.introduce,
.activity-title {
  color: #172b4d;
}

.left-row-panel > .el-row > .el-col:first-child,
.activity-items > .el-col:first-child {
  color: #5e6c84;
}
.sub-title {
  padding-bottom: 10px;
  margin-top: 24px;
  border-bottom: 2px solid #ebecf0;
}
.classDetail {
  overflow: auto;
  height: 80px;
  cursor: pointer;
  -webkit-transition: all .25s;
  -moz-transition: all .25s;
  -ms-transition: all .25s;
  -o-transition: all .25s;
  transition: all .25s;

  &:hover {
    background: #eee;
 }
}
.overflow {
  height: 16px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
</style>

<style lang="scss">
.range-class {
  .el-dialog {
    min-width: 290px;
  }
}
</style>
